package com.yb0os1.strategy.enums;

import java.util.function.IntPredicate;

public enum MemberType {
    Ordinary(recharge->recharge>0&&recharge<=1000),
    Gold(recharge->recharge>1000&&recharge<=10000),
    Platinum(recharge->recharge>10000&&recharge<=100000),
    Diamond(recharge->recharge>100000&&recharge<=1000000),
    Super(recharge->recharge>1000000);

    private final IntPredicate predicate;

    //IntPredicate就是接收一个lambda表达式
    MemberType(IntPredicate predicate){
        this.predicate = predicate;
    }

    public static MemberType getMemberType(int recharge){
        for(MemberType memberType:MemberType.values()){
            if(memberType.predicate.test(recharge)){
                return memberType;
            }
        }
        return null;
    }
}
